/*
 * ContribuyentesGraficaTotalesCorregimientosFrame.java
 *
 * Created on 8 de mayo de 2008, 09:18 PM
 */

package org.vehiculos.reportes;

import org.mybeans.Sesion;
 
import java.util.HashMap;
import java.util.Map;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
 import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author  avbravo
 */
public class VehiculosGraficaTotalesCorregimientosFrame extends javax.swing.JFrame {
Sesion sesion;
    /** Creates new form ContribuyentesGraficaTotalesCorregimientosFrame */
    public VehiculosGraficaTotalesCorregimientosFrame() {
        initComponents();
        sesion = new Sesion();
         /*
         * Fondo
         */

         
         
         

        jXPanel1.setOpaque(false);
        setContentPane(jXPanel1);
        /*
         * fondo
         */
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jButtonPrevio = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jButtonImprimir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Grafica de Total de vehiculos por corregimientos");

        jButtonPrevio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/preview.png"))); // NOI18N
        jButtonPrevio.setToolTipText("Vista Previa");
        jButtonPrevio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPrevioActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jButtonImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/print.jpeg"))); // NOI18N
        jButtonImprimir.setToolTipText("Imprimir");
        jButtonImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonImprimirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonPrevio, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(43, Short.MAX_VALUE))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonPrevio, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonPrevioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPrevioActionPerformed
 
    String reportSource;
    reportSource = sesion.getRutaReportes() + "VehiculosGraficaTotalesCorregimiento.jrxml";
    String reportDest;
    reportDest = sesion.getRutaDestino() + "VehiculosGraficaTotalesCorregimiento.html";

    Map<String, Object> params = new HashMap<String, Object>();

    try {
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        // JasperPrint jasperPrint =
        //JasperFillManager.fillReport(
        //jasperReport, params, new JREmptyDataSource());
        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);
        // JasperExportManager.exportReportToHtmlFile(
        //     jasperPrint, reportDest);

        JasperViewer.viewReport(jasperPrint, false);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonPrevioActionPerformed

private void jButtonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImprimirActionPerformed
 

    String reportSource;
    reportSource = sesion.getRutaReportes() + "VehiculosGraficaTotalesCorregimiento.jrxml";
    String reportDest;
    reportDest = sesion.getRutaDestino() + "VehiculosGraficaTotalesCorregimiento.html";

    Map<String, Object> params = new HashMap<String, Object>();

    try {
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
params.put("P_MUNICIPIO", sesion.getMunicipio());
        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);
//        JasperViewer.viewReport(jasperPrint, false);
        JasperPrintManager.printReport(jasperPrint, true);
    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonImprimirActionPerformed

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed
 
    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VehiculosGraficaTotalesCorregimientosFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonImprimir;
    private javax.swing.JButton jButtonPrevio;
    private javax.swing.JButton jButtonRegresar;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    // End of variables declaration//GEN-END:variables

}
